<template>
  <div id="app">
    <el-button type="primary" @click="download">下载</el-button>
  </div>
</template>

<script>
import studentApi from './api/student'
export default {
  name: 'App',
  methods: {
    async download () {
      const result = await studentApi.downloadExcle()
      let blob = new Blob([result], {
        type:
          'aapplication/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8'
      })
      let element = document.createElement('a')
      element.setAttribute('href', window.URL.createObjectURL(blob)) //创建下载的链接
      //后端需设置headers.add("Access-Control-Expose-Headers", "Content-Disposition");
      let filename = result.headers['content-disposition']
        .split(';')[1]
        .split('=')[1]
      element.setAttribute('download', filename)
      element.style.display = 'none'
      element.click()
    }
  }
}
</script>

<style></style>
